<template>
  <div>

    <!-- 面包屑导航条 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>信任设备管理</el-breadcrumb-item>
      <el-breadcrumb-item>场景字典管理</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 卡片视图 -->
    <el-card class="box-card">
      <!-- 头部的搜索和添加区域 -->
      <el-row :gutter="20">
        <el-col :span="7">
          <el-input placeholder="请输入内容" v-model="queryinfo.query">
            <el-button slot="append" icon="el-icon-search" @click="getSceneList()"></el-button>
          </el-input>
        </el-col>
        <el-col :span="4">
          <el-button type="primary" @click="addDialogVisible=true">添加场景字典</el-button>
        </el-col>
      </el-row>

      <!-- 表格区域 -->
      <el-table
        :data="sceneDictlist"
        border
        stripe
        style="width: 100%">
        <el-table-column
          type="index">
        </el-table-column>
        <el-table-column
          prop="sceneName"
          label="场景类型"
          width="120">
        </el-table-column>
        <el-table-column
          prop="sceneCode"
          label="场景编码"
          width="120">
        </el-table-column>
        <el-table-column
          label="状态">
          <!-- 让这一行的开关，把状态绑定到 这一行数据的 mg_state 上 -->
          <!-- <el-switch
            v-model="scope.row.mg_state"
            @change="(newState) => {switchChanged(newState, scope.row.id)}"
            slot-scope="scope">
          </el-switch> -->
          <el-switch
            v-model="scope.row.state"
            @change="switchChanged2(scope.row.state, scope.row.id)"
            slot-scope="scope">
          </el-switch>
        </el-table-column>
        <el-table-column
          width="185"
          label="操作">
          <template slot-scope="scope">
            <el-button type="primary" icon="el-icon-edit" size="mini" @click="showEditDialog(scope)"></el-button>
            <el-button type="danger" icon="el-icon-delete" size="mini" @click="remove(scope)"></el-button>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页区域 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryinfo.pagenum"
        :page-sizes="[2, 5, 10, 15]"
        :page-size="queryinfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </el-card>

    <!-- 添加用户的对话框 -->
    <el-dialog
      title="添加场景字典"
      :visible.sync="addDialogVisible"
      width="50%"
      @close="addDialogClosed">
      <!-- 添加用户的表单 -->
      <el-form :model="addForm" :rules="addFormRules" ref="addFormRef" label-width="100px">

        <el-form-item label="场景类型" prop="sceneName">
          <el-input v-model="addForm.sceneName"></el-input>
        </el-form-item>
        <el-form-item label="场景编码" prop="sceneCode">
          <el-input v-model="addForm.sceneCode"></el-input>
        </el-form-item>
        <el-form-item label="状态" prop="state">
          <el-switch
            v-model="addForm.state"
            slot-scope="scope">
          </el-switch>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="addDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="addSceneDict">确 定</el-button>
      </span>
    </el-dialog>

    <!-- 编辑用户的对话框 -->
    <el-dialog
      title="修改场景信息"
      :visible.sync="editDialogVisible"
      width="50%"
      @close="editDialogClosed">
      <!-- 编辑用户的表单 -->
      <el-form :model="editForm" :rules="editFormRules" ref="editFormRef" label-width="100px">
        <el-form-item label="场景类型" prop="sceneName">
          <el-input v-model="editForm.sceneName" ></el-input>
        </el-form-item>
        <el-form-item label="场景编码" prop="sceneCode">
          <el-input v-model="editForm.sceneCode" disabled></el-input>
        </el-form-item>

        <el-form-item label="状态" prop="state">
          <el-switch
            v-model="editForm.state"
            slot-scope="scope">
          </el-switch>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="editDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="editDict">确 定</el-button>
      </span>
    </el-dialog>


  </div>
</template>

<script>
  import mix from './Dict-mixins.js'
  export default {
    mixins: [mix]
  }
</script>

<style lang="less" scoped>
  .red {
    color: red;
  }

  .green {
    color: lightseagreen;
  }

  .zk-table {
    margin-top: 15px;
  }

  .el-cascader {
    width: 100%;
  }
</style>
